/*
 * *****************************************************************************
 *  Copyright ( c ) 2019 huibur Inc. All Rights Reserved.
 *
 *  This software is the confidential and proprietary information of Huibur Inc
 *  (*Confidential Information*). You shall not disclose such Confidential Information
 *  and shall use it only in accordance with the terms of the license agreement
 *  you entered into with Huibur or a Huibur authorized
 *  reseller (the "License Agreement*).
 *  ******************************************************************************
 */

package com.huibur.devicecheck.controller;

import com.huibur.devicecheck.enums.ResultCodeEnum;
import com.huibur.devicecheck.exception.ParameterSettingErrorException;
import com.huibur.devicecheck.exception.RemindTimeSettingErrorException;
import com.huibur.devicecheck.model.param.SysParamsParam;
import com.huibur.devicecheck.model.po.SysParamsPO;
import com.huibur.devicecheck.request.ObjRes;
import com.huibur.devicecheck.service.ISysParamsService;
import com.huibur.devicecheck.service.impl.SysParamsServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/*******************************************************
* Title: SysParamsController.java
* Description:
* @author baiqingshuo
* @date 2021/10/12
* @version 1.0
*******************************************************/

@RestController
@RequestMapping("/sysParams")
@Api(value = "参数设置",tags = {"参数设置"})
@Slf4j
public class SysParamsController {

    @Autowired
    ISysParamsService isysParamsService;

    /**
     * 编辑参数设置
     * @param
     * @param sysParamsParam
     * @return
     */
    @PutMapping("")
    @ApiOperation(value = "编辑参数设置", response = ObjRes.class)
    public ObjRes<Void> updateSysParams(SysParamsParam sysParamsParam) {
        try {
            return isysParamsService.updateSysParams(sysParamsParam);
        } catch (ParameterSettingErrorException e) {
            log.error(e.getMessage());
            return new ObjRes(ResultCodeEnum.PARAMETER_SETTING_ERROR.getCode(), ResultCodeEnum.PARAMETER_SETTING_ERROR.getLabel());
        } catch (RemindTimeSettingErrorException e) {
            log.error(e.getMessage());
            return new ObjRes(ResultCodeEnum.REMIND_TIME_SETTING_ERROR.getCode(), ResultCodeEnum.REMIND_TIME_SETTING_ERROR.getLabel());
        }
    }

    /**
     * 获取系统参数设置
     * @return
     */
    @GetMapping("/selectData")
    @ApiOperation(value = "获取系统参数设置")
    public ObjRes<SysParamsPO> selectData() {
        return new ObjRes<SysParamsPO>().data(isysParamsService.selectData());
    }
}
